<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>采购订单管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!--列表-->
    <el-table size="small" :data="orderList" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" prop="id" label="订单编号" width="100">
      </el-table-column>
      <el-table-column align="center" prop="goodsName" label="商品名" width="150">
      </el-table-column>
      <el-table-column align="center" prop="goodsSerialNumber" label="商品编号" width="200"></el-table-column>
      <el-table-column align="center" prop="goodsPrice" label="进价（元）" width="100"></el-table-column>
      <el-table-column align="center" prop="amount" label="数量" width="150"></el-table-column>
      <el-table-column sortable align="center" prop="status" label="是否已经采购" width="100">
        <template slot-scope="scope">
          <span :style="{color: scope.row.status ? '#4fc08d' : '#ff6600'}">{{scope.row.status ? '已采购' : '未采购'}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="200">
        <template slot-scope="scope">
          <el-button size="mini" type="success" @click="nowPurchase(scope.$index, scope.row)">立即采购</el-button>
          <el-button size="mini" type="warning" @click="discPurchase(scope.$index, scope.row)">修改</el-button>
          <el-button size="mini" type="danger" @click="deletePurchase(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageQuery" @callFather="callFather"></Pagination>
    <el-dialog title="修改采购单" :visible.sync="dialog" width="30%">
      <el-input-number v-model="good.amount" @change="handleChange" :min="0" style="width: 50%;"></el-input-number>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" :loading="loading" class="title" @click="sureChange">确认修改</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Pagination from '../../components/Pagination'
export default {
  name:'ManagerOrder',
  data() {
    return {
      dialog: false,
      good: {},
      orderList: [], //用户列表
      pageQuery: {
        pageNum: 1,
        pageSize: 10
      },
      loading: false //是显示加载
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  created() {
    this.getOrderList()
  },
  methods: {
    /**
     * 获取用户列表
     */
    getOrderList() {
      this.loading = true
      this.$api.manager.purchaseList(this.pageQuery).then(res => {
        if (res.code === 200) {
          this.orderList = res.data.records
          this.loading = false
        }
      }).catch(err => this.loading = false)
    },
    /**
     * 分页插件事件
     */
    callFather(parm) {
      this.pageQuery.pageNum = parm.currentPage
      this.pageQuery.pageSize = parm.pageSize
      this.getOrderList()
    },
    /**
     * 立即采购
     */
    nowPurchase (index, good) {
      let params = {
        purchaseOrderId: good.id
      }
      this.$api.manager.godownEntryAdd(params).then(res => {
        if (res.code === 200) {
          this.$message({
            type: 'success',
            message: '已生成入库单'
          })
          this.$router.push({
            path: '/manager/entry'
          })
        }
      })
    },
    /**
     * 修改采购单
     */
    discPurchase (index, good) {
      this.dialog = true
      this.good = good
    },
    handleChange (val) {
    },
    sureChange () {
      let params = {
        id: this.good.id,
        amount: this.good.amount
      }
      this.$api.manager.discPurchase(params).then(res => {
        if (res.code === 200) {
          this.dialog = false
        }
      })
    },
    /**
     * 删除采购订单
     */
    deletePurchase (index, order) {
      let params = {
        id: order.id
      }
      this.$api.manager.deletePurchase(params).then(res => {
        if (res.code === 200) {
          this.getOrderList()
        }
      })
    }
  }
}
</script>

<style>
.comment-search {
  margin-top: 20px;
}
.commentRole {
  width: 100%;
}
</style>

 
 